<template>
  <view>
    <!--
    <u-navbar bgColor='#4871C0' :titleStyle="{ color: '#FFF'}" title="新建党总支活动" leftIconColor="#FFF"
      @rightClick="rightClick" :autoBack="true">
    </u-navbar>
    -->
    <div class="newForm">

      <div class="form">
        <u-cell title="活动室" :isLink="true" arrow-direction="right" :value="room ?room.name:''"
                @click="openRoom"></u-cell>
        <u-cell title="活动时间" :isLink="true" :value="date" arrow-direction="right" @click="callPicker"></u-cell>
        <!--日期选择器-->
        <picker-date v-if="showdayTime" :value="showdayTime" mode="time" :startTime="startDate" :endTime="endDate"  :defaultTime="today" :params="params" @confirm="bindDateChange($event)" confirm-color="#4871C0">
        </picker-date>
        <!-- <u-cell title="签到方式" :isLink="true" :value="form.sign_way_str" style='border:0' @click="openSignWay">
        </u-cell> -->
        <u-cell title="签到方式" :value="form.sign_way_str" style='border:0'>
        </u-cell>
        <!-- <u-cell title="活动中是否有物品领取" :isLink="true" value="有">
        </u-cell>
        <u--input class='ipt' placeholder="请输入物品名称" border="surround" v-model="value" @change="change">
        </u--input> -->
        <div class='line'></div>
		<div class='textarea'v-if="room&&!room.manager">
		  <p>活动地点</p>
		  <u--textarea v-model="form.place_huodong" placeholder="请输入活动地点" autoHeight></u--textarea>
		</div>
        <div class='textarea' v-if="room&&!room.manager">
          <p>班级</p>
          <u--textarea v-model="form.banji" placeholder="请输入班级" autoHeight></u--textarea>
        </div>
        <div class='textarea'>
          <p>活动主题</p>
          <u--textarea v-model="form.title" placeholder="请输入活动主题" autoHeight></u--textarea>
        </div>
        <div class='textarea'>
          <p>活动内容</p>
          <u--textarea v-model="form.content" placeholder="请输入活动内容" autoHeight></u--textarea>
        </div>
        <div class='textarea'>

          <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" accept="file"
                    :maxCount="1" name="1">
            <span v-if="!show_files" class="pic_user" style="margin-left: 20px;"></span>
            <div style="position: relative" v-if="show_files">
              <div class="file-name " @click.stop="handleDownload(form.files)">
                <u-icon name="attach" color="#4871C0" size="24"></u-icon>
                <label class="file-txt">{{ form.files ? form.files.filename : "" }}</label>
              </div>
              <view class="new-tip" @click.stop="deleteclick(form.files)">
                <u--image :src="delete_icon" width="40rpx" height="28rpx">
                </u--image>
              </view>
            </div>
            <p>上传附件</p>
          </u-upload>
          <view class="tishititle">仅支持上传word、excel、ppt、pdf、图片类型的文件</view>
        </div>

        <u-cell title="更多配置" :isLink="true" arrow-direction="right" @click="moreConfigure"></u-cell>
        <div class='line'></div>
        <!-- 发起人 -->
        <div class="sponsor_box">
          <div class="uni-list-cell-left" style="margin-bottom: 8px;">发起人</div>
          <view class="imgs-box u-flex">
            <div class="user-img">
              <view class="item-img-bg" v-if="info.user&&info.user.nickname">{{strFormat(info.user.nickname)}}</view>
              <!-- <img :src="info.user.avatar" shape="circle" /> -->
            </div>
            <!--<span class="pic_user" @click="pickUser('user')"></span>-->
          </view>
        </div>
        <!-- 参加人 -->
        <div class="sponsor_box">
          <div class="uni-list-cell-left" style="margin-bottom: 8px;">
            参加人({{ info.attend_meet_ids_user?info.attend_meet_ids_user.length:'' }})
          </div>
          <view class="imgs-box u-flex" v-if="!show_attend_meet">
            <div class="user-img" v-for="(v, i) in info.attend_meet_ids_user" v-if="i<5">
              <!-- <i class="del" @click="delUser('attend_meet',i)"></i> -->
              <!-- <img :src="v.avatar" shape="circle" /> -->
              <view class="item-img-bg">{{strFormat(v.nickname)}}</view>
            </div>
            <span v-if="info.type == 5" class="pic_user" @click="pickUser('attend_meet')"></span>

          </view>

          <view class="imgs-box u-flex" v-if="show_attend_meet">
            <div class="user-img" v-for="(v, i) in info.attend_meet_ids_user">
              <!-- <i class="del" @click="delUser('attend_meet',i)"></i> -->
              <!-- <img :src="v.avatar" shape="circle" /> -->
              <view class="item-img-bg">{{strFormat(v.nickname)}}</view>
            </div>
            <!-- <span class="pic_user" @click="pickUser('attend_meet')"></span> -->
          </view>

          <div class='all' v-if=" info.attend_meet_ids_user&&info.attend_meet_ids_user.length > 5"
               @click="show_attend_meet  = !show_attend_meet">{{ show_attend_meet ? '收起全部' : '展开全部' }}
          </div>
        </div>
        <div class='line' v-if="info.type == 1 || info.type == 2"></div>
        <!-- 议题参会人 -->
        <div class="sponsor_box" v-if="info.type == 1 || info.type == 2">
          <div class="uni-list-cell-left" style="margin-bottom: 8px;">
            议题参与人({{ info.attend_topic_ids_user?info.attend_topic_ids_user.length:'' }})
          </div>
          <view class="imgs-box u-flex" v-if="!show_attend_topic">
            <div class="user-img" v-for="(v, i) in info.attend_topic_ids_user" v-if="i<5">
              <!-- <i class="del" @click="delUser('attend_topic',i)"></i> -->
              <!-- <img :src="v.avatar" shape="circle" /> -->
              <view class="item-img-bg">{{strFormat(v.nickname)}}</view>
            </div>
            <!-- <span class="pic_user" color="#666666" size="16" @click="pickUser('attend_topic')"></span> -->
          </view>
          <view class="imgs-box u-flex" v-if="show_attend_topic">
            <div class="user-img" v-for="(v, i) in info.attend_topic_ids_user">
              <!-- <i class="del" @click="delUser('attend_topic',i)"></i> -->
              <!-- <img :src="v.avatar" shape="circle" /> -->
              <view class="item-img-bg">{{strFormat(v.nickname)}}</view>
            </div>
            <!-- <span class="pic_user" color="#666666" size="16" @click="pickUser('attend_topic')"></span> -->
          </view>
          <div class='all' v-if=" info.attend_topic_ids_user.length > 5"
               @click=" show_attend_topic= !show_attend_topic ">{{ show_attend_topic ? '收起全部' : '展开全部' }}
          </div>
        </div>
        <div class='line'></div>
        <!-- 审批人 -->
        <div class="sponsor_box" v-if="room&&room.manager">
          <div class="uni-list-cell-left" style="margin-bottom: 8px;">审批流程
            <span style="font-size:12px;color:#999">（已由管理员预设不可修改）</span>
          </div>
          <p class="check_men">功能室管理员</p>
          <view class="imgs-box2 u-flex">
            <div class="user-img">
              <view class="item-img-bg">{{room&&room.manager&&room.manager.nickname?room.manager.nickname:room.manager_name}}</view>
              <!-- <img :src="room ?room.manager.avatar:''" shape="circle" /> -->
              <!-- {{ room.manager.nickname }} -->
            </div>
          </view>
        </div>
        <div class='line' v-if="room&&room.manager"></div>
        <!-- 校长 -->
        <div class="sponsor_box" v-if="room&&room.manager">
          <div class="uni-list-cell-left" style="margin-bottom: 8px;">
            校长
          </div>
          <view class="imgs-box u-flex">
            <div class="user-img" v-for="(v, i) in info.check_ids_user">
              <!-- <img :src="v.avatar" shape="circle" /> -->
              <view class="item-img-bg">{{strFormat(v.nickname)}}</view>
            </div>
          </view>
          <!-- <view class="imgs-box u-flex" v-if="!show_check_ids_user">
            <div class="user-img" v-for="(v, i) in info.check_ids_user" v-if="i<5">
              <i class="del" @click="delUser('check_ids_user',i)"></i><img :src="v.avatar"
                shape="circle" />
            </div>
            <span class="pic_user" color="#666666" size="16" @click="pickUser('check')"></span>
          </view>
          <view class="imgs-box u-flex" v-if="show_check_ids_user">
            <div class="user-img" v-for="(v, i) in info.check_ids_user">
              <i class="del" @click="delUser('check',i)"></i><img :src="v.avatar" shape="circle" />
            </div>
            <span class="pic_user" color="#666666" size="16" @click="pickUser('check')"></span>
          </view>
          <div class='all' v-if=" info.check_ids_user.length > 5"
            @click=" show_check_ids_user= !show_check_ids_user ">{{ show_check_ids_user ? '收起全部' : '展开全部' }}
          </div> -->
        </div>
        <div class="sponsor_box"  v-if="room&&room.manager">
          <div class="uni-list-cell-left" style="margin-bottom: 8px;">
            签发人
          </div>
          <view class="imgs-box u-flex">
            <div class="user-img" v-for="(v, i) in info.issued_ids_user">
              <!-- <img :src="v.avatar" shape="circle" /> -->
              <view class="item-img-bg">{{strFormat(v.nickname)}}</view>
            </div>
          </view>
          <!-- <view class="imgs-box u-flex" v-if="!show_issued_ids_user">
            <div class="user-img" v-for="(v, i) in info.issued_ids_user" v-if="i<5">
              <i class="del" @click="delUser('attend_topic',i)"></i><img :src="v.avatar" shape="circle" />
            </div>
            <span class="pic_user" color="#666666" size="16" @click="pickUser('issued')"></span>
          </view>
          <view class="imgs-box u-flex" v-if="show_issued_ids_user">
            <div class="user-img" v-for="(v, i) in info.issued_ids_user">
              <i class="del" @click="delUser('issued',i)"></i><img :src="v.avatar" shape="circle" />
            </div>
            <span class="pic_user" color="#666666" size="16" @click="pickUser('issued')"></span>
          </view>
          <div class='all' v-if=" info.issued_ids_user.length > 5"
            @click=" show_issued_ids_user= !show_issued_ids_user ">
            {{ show_issued_ids_user ? '收起全部' : '展开全部' }}
          </div> -->
        </div>
        <div class="btn">
          <!-- <mt-button @click="post" size="small" type="primary">提交</mt-button> -->
          <u-button class='cancelbtn' @click="submitDraft">保存草稿</u-button>
          <u-button type="primary" @click="submitData" text="提交审核" color='#4871C0'></u-button>

        </div>
      </div>
    </div>


    <u-popup :show="showSignWay" mode="bottom" @close="closeSignWay" @open="openSignWay" :closeable="true"
             :border-radius="10" close-icon-color="#010101" :mask-close-able="false" close-icon-size="42">
      <view class="content" style="height:60%">
        <!-- <u-icon name="checkbox-mark" color="#4871C0" size="28"></u-icon> -->
        <view class="title">请选择签到类型</view>
        <view @click="selSignWay(v)" :class="sign_way==v.id?'meet active':'meet '"
              v-for="(v, i) in signWayList">
          {{ v.txt }}
          <text>
            <img src="@/static/assets/images/dui.png" v-if="sign_way==v.id" /></text>
        </view>

        <view class="btn">
          <u-button class='cancelbtn' @click="closeSignWay">取消</u-button>
          <u-button type="primary" text="确定" @click="sureSignWay" color='#4871C0'></u-button>
        </view>
      </view>
    </u-popup>


    <u-popup :show="showRoom" mode="bottom" @close="closeRoom" @open="openRoom" :closeable="true"
             :border-radius="10" close-icon-color="#010101" :mask-close-able="false" close-icon-size="42">
      <view class="content">
        <!-- <u-icon name="checkbox-mark" color="#4871C0" size="28"></u-icon> -->
        <view class="title">请选择活动室</view>
        <view style="height:300px; overflow: scroll;">
          <view @click="selRoom(v)" :class="room_id ==v.id?'meet active':'meet '" v-for="(v, i) in roomList">
            {{ v.edifice ? v.edifice.name : v.title }}
            <text>
              <img src="@/static/assets/images/dui.png" v-if="room_id==v.id" /></text>
          </view>
        </view>
        <view class="btn">
          <u-button class='cancelbtn' @click="closeRoom">取消</u-button>
          <u-button type="primary" text="确定" @click="sureRoom" color='#4871C0'></u-button>
        </view>
      </view>
    </u-popup>

    <u-popup :show="showTime" mode="bottom" @close="closeTime" @open="openTime" :closeable="true"
             :border-radius="10" close-icon-color="#010101" :mask-close-able="false" close-icon-size="42">
      <view class="content" style="height:60%">
        <view>
          <picker-view :value="seledTime" :indicator-style="indicatorStyle" @change="bindChange"
                       class="picker-view">
            <picker-view-column>
              <view class="item" v-for="(v, i) in timeList">
                {{ v.start_time.substring(11).replace(":00", "").replace(":0", ":00") }}
              </view>
            </picker-view-column>
            <picker-view-column>
              <view class="item">--</view>
            </picker-view-column>
            <picker-view-column>
              <view class="item" v-for="(v, i) in timeList">
                {{ v.end_time.substring(11).replace(":00", "") }}
              </view>
            </picker-view-column>
          </picker-view>
        </view>
        <view class="btn">
          <u-button class='cancelbtn' @click="closeTime">取消</u-button>
          <u-button type="primary" text="确定" @click="sureTime" color='#4871C0'></u-button>
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script>
import {
  getDefData,
  getUserList,
  meetAdd,
  getMeetTypesList,
  getRoomList,
  getRoomDetail
} from '@/api/roomApi.js'

export default {
  data() {

    //var date = this.format("yyyy-mm-dd");
    var d = new Date();
    var year = d.getFullYear();
    var month = d.getMonth() + 1;
    var day = d.getDate();
    var weeks = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
    return {
      delete_icon: require('@/static/delete.png'),
      form: {},
      info: {},
      seledTime: [0, 0, 0],
      today: "",
      indicatorStyle: `height: ${Math.round(uni.getSystemInfoSync().screenWidth / (750 / 100))}px;`,
      showRoom: false,
      showTime: false,
      show_files: false,
      show_attend_meet: false,
      show_attend_topic: false,
      show_check_ids_user: false,
      show_issued_ids_user: false,
      showSignWay: false,
      showdayTime:false,
      signWayList: [],
      timeList: [],
      roomList: [],
      meet_type: 0,
      sign_way: 0,
      room_id: uni.getStorageSync('room_id'),
      room: uni.getStorageSync('room_info'),
      date: "",
      date2: "",
      fileList1: [],
      array: ['请选择', '第一活动室', '第二活动室', '第三活动室', '第四活动室'],
      index: 0,
      type: "",
      attend_topic_wx_ids: "",
      attend_meet_wx_ids: "",
      params: {
        year: true,
        month: true,
        day: true,
        hour: false,
        minute: false,
        second: false,
        // 选择时间的时间戳
        timestamp: true,
      },
    };
  },

  watch: {},

  computed: {
    startDate() {
      return this.getDate('start');
    },
    endDate() {
      return this.getDate('end');
    }
  },
  onLoad() {
    console.log("room_info",uni.getStorageSync('room_info'))
    console.log("=====room&&room.manager",this.room,(this.room.manager))
  },
  onShow() {
    console.log("111", this.form)
    if (uni.getStorageSync('ext_data')) {
      this.form = Object.assign(this.form, uni.getStorageSync('ext_data'));
      console.log("ext_data11",this.form)
      // this.form.late_time = this.form.late_time.join("-");
      // this.form.normal_time = this.form.normal_time.join("-");
    }
    var userlist = uni.getStorageSync('sel_user_list');
    var ids = '';
    var users = [];
    for (var i = 0; i < userlist.length; i++) {
      ids = i == 0 ? userlist[i].id : ids + "," + userlist[i].id;
    }
    users = userlist;
    if (this.type == "attend_meet") {
      this.form.attend_meet_ids = ids;
      this.info.attend_meet_ids_user = users;
      this.form.attend_meet_wx_ids=ids;
    } else if (this.type == "attend_topic") {
      this.form.attend_topic_ids = ids;
      this.info.attend_topic_ids_user = users;
      this.form.attend_topic_wx_ids=ids;
    } else if (this.type == "check") {
      this.form.check_ids = ids;
      this.info.check_ids_user = users;
    } else if (this.type == "issued") {
      this.form.issued_ids = ids;
      this.info.issued_ids_user = users;
    }
  },
  onReady() {
    this.getToday();
    this.getTimeStr();
    this.getDefDatas();
    this.getRoom();
  },
  updated: function() {

  },
  methods: {
    strFormat(str){
      if(str.length>3){
        return str.substring(0,3)+'...';
      }else{
        return str
      }
    },
    // 点击附件预览
    handleDownload(item) {
      console.log("=====item", item)
      let params = {
        url: item.fullurl, // 需要预览文件的地址(必填，可以使用相对路径)
        name: item.filename, // 需要预览文件的文件名(不填的话取url的最后部分)
        size: item.filesize, // 需要预览文件的字节大小(必填)
        type: item.mimetype
      }
      this.$store.dispatch('yulan', params)
    },
    getDate(type) {
      const date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();

      if (type === 'start') {
        year = year - 0;
      } else if (type === 'end') {
        year = year + 20;
      }
      month = month > 9 ? month : '0' + month;
      day = day > 9 ? day : '0' + day;
      console.log("=====================getDate======================")
      return `${year}-${month}-${day}`;
    },
    getToday() {
      var d = new Date();
      // 获取年，getFullYear()返回4位的数字
      var year = d.getFullYear();
      // 获取月，月份比较特殊，0是1月，11是12月
      var month = d.getMonth() + 1;
      // 变成两位
      month = month < 10 ? '0' + month : month;
      // 获取日
      var day = d.getDate();
      day = day < 10 ? '0' + day : day;
      this.today = (year + '-' + month + '-' + day);
    },

    openRoom() {
      this.showRoom = true;
    },
    closeRoom() {
      this.showRoom = false;
    },
    sureRoom() {
      this.showRoom = false;
      this.room = uni.getStorageSync('room_info');
    },
    selRoom(item) {
      this.room_id = item.id;
      uni.setStorageSync('room_id', item.id)
      uni.setStorageSync('room_info', item)
    },

    getRoom() {
      const _this = this;
      _this.$indicator.open("加载中...");
      let params = {};
      params.date = this.date.substring(0, 10);
      params.id = uni.getStorageSync('room_id');

      getRoomList(params).then(res => {
        console.log(res)
        _this.roomList = res.data;
        _this.$indicator.close();
      })
    },

    openTime() {
      this.showdayTime = false;
      this.showTime = true;
    },
    closeTime() {
      this.showTime = false;
    },

    bindChange: function(e) {
      const val = e.detail.value;
      console.log("============>>>>", val);
      this.seledTime = val;
    },
    sureTime(e) {
      var val = this.seledTime;
      uni.setStorageSync('start_time', this.timeList[val[0]].start_time);
      uni.setStorageSync('end_time', this.timeList[val[2]].end_time);
      if (Number(new Date(this.timeList[val[0]].start_time)) > Number(new Date(this.timeList[val[2]]
          .end_time))) {
        uni.setStorageSync('end_time', this.timeList[val[0]].start_time);
        uni.setStorageSync('start_time', this.timeList[val[2]].end_time);
      }

      this.getTimeStr();
      this.showTime = false;
    },

    callPicker(id) {
     this.showdayTime = true;
    },
    bindDateChange: function(e) {
      const _this = this;
      this.date2 = `${e.year}-${e.month}-${e.day}`;
      let params = {};
      params.date = `${e.year}-${e.month}-${e.day}`;
      params.id = uni.getStorageSync('room_id');
      getRoomDetail(params).then(res => {
        _this.timeList = res.data.res;
        var timeList = [];
        for (let index in _this.timeList) {
          for (let key in this.timeList[index]) {
            if (this.timeList[index][key].state.code == 1) {
              timeList.push(this.timeList[index][key]);
            }
          }
        }
        _this.timeList = timeList;
      })
      this.openTime();
    },
    openSignWay() {
      this.showSignWay = true;
    },
    closeSignWay() {
      this.showSignWay = false;
    },
    sureSignWay() {
      this.showSignWay = false;
      var item = uni.getStorageSync('sign_way');
      this.form.sign_way_str = item.txt;
      this.form.sign_way = item.id;
    },

    selSignWay(item) {
      this.sign_way = item.id;
      uni.setStorageSync('sign_way', item)
    },

    getWeekday(sDate) {
      var dt = new Date(sDate.replace(/-/g, '/'));
      var week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
      var a = ['0', '1', '2', '3', '4', '5', '6'];
      return week[a[dt.getDay()]];
    },
    // 获取时间字符串
    getTimeStr() {
      var start_time = uni.getStorageSync('start_time').split(" ");
      var end_time = uni.getStorageSync('end_time').split(" ");
      this.date = start_time[0] + " " + this.getWeekday(uni.getStorageSync('start_time')) + " " + start_time[1] +
          " - " + end_time[1];

      var now = new Date(Number(new Date(uni.getStorageSync('start_time'))) - 30 * 60 * 1000);
      var now2 = new Date(Number(new Date(uni.getStorageSync('start_time'))));
      var now3 = new Date(Number(new Date(uni.getStorageSync('start_time'))));
      var now4 = new Date(Number(new Date(uni.getStorageSync('start_time'))) + 15 * 60 * 1000);
      // this.time1 = [now.getHours()+ ":"+ now.getMinutes() ,now2.getHours()+ ":"+ now2.getMinutes()];
      this.form.normal_time = [(now.getHours() < 10 ? "0" + now.getHours() : now.getHours()) + ":" + (now
          .getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes()), (now2.getHours() < 10 ? "0" +
          now2.getHours() : now2.getHours()) + ":" + (now2.getMinutes() < 10 ? "0" + now2.getMinutes() :
          now2.getMinutes())];
      this.form.late_time = [(now3.getHours() < 10 ? "0" + now3.getHours() : now3.getHours()) + ":" + (now3
          .getMinutes() < 10 ? "0" + now3.getMinutes() : now3.getMinutes()), (now4.getHours() < 10 ?
          "0" + now4.getHours() : now4.getHours()) + ":" + (now4.getMinutes() < 10 ? "0" + now4
          .getMinutes() : now4.getMinutes())];

    },

    getDefDatas() {
      const _this = this;
      uni.removeStorageSync('sel_user_list');
      getDefData({
        id: uni.getStorageSync('type_id'),
        room_id: this.room_id,
      }).then(res => {
        console.log(res)
        _this.signWayList = res.data.sign_way;
        _this.signWayList.unshift({
          id: "0",
          txt: "无"
        })
        _this.info = res.data.info;
        _this.form.absence_tip = res.data.tip.absence_tip;
        _this.form.late_tip = res.data.tip.late_tip;
        _this.form.normal_tip = res.data.tip.normal_tip;


        _this.form.attend_meet_ids = res.data.info.attend_meet_ids;
        _this.form.attend_meet_wx_ids = res.data.info.attend_meet_wx_ids;
        _this.form.attend_topic_wx_ids = res.data.info.attend_topic_wx_ids;
        _this.form.attend_topic_ids = res.data.info.attend_topic_ids;
        _this.form.check_ids = res.data.info.check_ids;
        _this.form.issued_ids = res.data.info.issued_ids;
        _this.form.sign_type = res.data.info.sign_type;
        _this.form.type_id = res.data.info.id;
        _this.form.sign_way = res.data.info.sign_type + "";
        _this.sign_way = res.data.info.sign_type + "";
        _this.form.sign_way_str = res.data.info.sign_type == 1 ? '页面签到' : res.data.info.sign_type ==
        2 ? '二维码签到' : '无';
        _this.form.room_id = uni.getStorageSync('room_id');
        _this.form.start_time = uni.getStorageSync('start_time');
        _this.form.end_time = uni.getStorageSync('end_time');
        uni.setStorageSync('def_data', res.data);
        uni.removeStorageSync('ext_data');

      })
    },
    //更多配置
    moreConfigure() {
      const url = "/pages/tabbar/meeting-room/add_huodong/moreConfigurations?huiyiData=" + JSON.stringify(this.form)
      uni.navigateTo({
        url: url,
      });
    },
    // 删除人员
    delUser(type, index) {
      const _this = this;
      if (type == "attend_meet") {
        this.info.attend_meet_ids_user.splice(index, 1);
        this.form.attend_meet_ids = [];
        this.form.attend_meet_wx_ids=[];
        this.info.attend_meet_ids_user.map(function(value, index) {
          _this.form.attend_meet_ids.push(value.id);
          _this.form.attend_meet_wx_ids.push(value.wx_userid||value.id);
        });
        console.log("= _this.form.attend_meet_ids==>", this.form.attend_meet_ids,this.form.attend_meet_wx_ids)
      } else if (type == "attend_topic") {
        this.info.attend_topic_ids_user.splice(index, 1);
        this.form.attend_topic_ids = [];
        this.form.attend_topic_wx_ids=[];
        this.info.attend_topic_ids_user.map(function(value, index) {
          _this.form.attend_topic_ids.push(value.id);
          _this.form.attend_topic_wx_ids.push(value.wx_userid||value.id);
        });
        console.log("= _this.form.attend_topic_ids==>", this.form.attend_topic_ids,this.form.attend_topic_wx_ids)
      } else if (type == "check") {
        this.info.check_ids_user.splice(index, 1);
        this.form.check_ids = [];
        this.info.check_ids_user.map(function(value, index) {
          _this.form.check_ids.push(value.id);
        });
        console.log("= _this.form.check_ids==>", this.form.check_ids)
      }
    },
    //选择人员
    pickUser(type) {
      this.type = type;
      var user_ids = 0;
      if (this.type == "attend_meet") {
        user_ids = this.form.attend_meet_wx_ids;
      } else if (this.type == "attend_topic") {
        user_ids = this.form.attend_topic_wx_ids;
      } else if (this.type == "check") {
        user_ids = this.form.check_ids;
      } else if (this.type == "issued") {
        user_ids = this.form.issued_ids;
      }
      console.log("选择人员", user_ids)
      uni.setStorageSync('sel_user_ids', "0," + user_ids);
      const url = "/pages/tabbar/meeting-room/change/index?user_ids=" + user_ids
      uni.navigateTo({
        url,
      });

    },
    submitDraft() {
      this.form.status = 0;
      this.submitData();
    },

    submitData() {
      if(this.room&&!this.room.manager){
        if(!this.form.banji){
          this.$toast("请填写班级");
          return
        }
        if(!this.form.place_huodong){
          this.$toast("请填写活动地址");
          return
        }
        if(!this.form.title){
          this.$toast("请填写活动主题");
          return
        }
        let titles = JSON.parse(JSON.stringify(this.form.title))
        this.form.title = this.form.banji+','+this.form.place_huodong+','+titles
      }
      this.form.start_time = uni.getStorageSync('start_time');
      this.form.end_time = uni.getStorageSync('end_time');
      this.form.meet_type = uni.getStorageSync('meet_type');

      if (Array.isArray(this.form.late_time)) {
        this.form.late_time = this.form.late_time.join("-");
      }
      if (Array.isArray(this.form.normal_time)) {
        this.form.normal_time = this.form.normal_time.join("-");
      }

      this.form.files = JSON.stringify(this.form.files);
      meetAdd(this.form).then(res => {

        if (res.code == 1) {
          if (this.form.status == 0) {
            this.$toast("保存成功");
            this.form.title  = '';
          } else {
            this.$toast(res.msg);
          }
          if (!Array.isArray(this.form.late_time)) {
            this.form.late_time = this.form.late_time.split('-');
          }
          if (!Array.isArray(this.form.normal_time)) {
            this.form.normal_time = this.form.normal_time.split("-");
          }
          let meetType = uni.getStorageSync('meet_type');
          console.log('meetType========' + meetType)
          if (meetType == 1) {
            uni.removeStorageSync('ext_data');
            uni.removeStorageSync('meet_type');

            setTimeout(() => {
              uni.setStorageSync('tab_cur_index', 1);
              uni.navigateTo({
                url: '/pages/tabbar/huodong/myhuiyi?tab_cur_index=1'
              })
              // uni.navigateBack({ ok: 1 });
            }, 2000)
          } else {
            uni.removeStorageSync('ext_data');
            uni.removeStorageSync('meet_type');
            // this.form.files = JSON.parse(this.form.files);

            setTimeout(() => {
              uni.setStorageSync('tab_cur_index', 1);
              uni.switchTab({
                url: '/pages/tabbar/tabbar-4/tabbar-4?tab_cur_index=1'
              })
              // uni.navigateBack({ ok: 1 });
            }, 2000)
          }

        } else {
          this.$toast(res.msg);
          // this.form.files = JSON.parse(this.form.files);
        }
      })
    },


    // 删除图片
    deletePic(event) {
      this[`fileList${event.name}`].splice(event.index, 1)
    },
    // 新增图片
    async afterRead(event) {
      let _this = this;
      // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
      let lists = [].concat(event.file)
      let fileListLen = this[`fileList${event.name}`].length
      lists.map((item) => {
        this[`fileList${event.name}`].push({
          ...item,
          status: 'uploading',
          message: '上传中'
        })
      })
      for (let i = 0; i < lists.length; i++) {
        const result = await this.uploadFilePromise(lists[i].url);
        console.log("result===>", result)
        var data = JSON.parse(result)

        if (data.code == 0) {
          _this.$toast(data.msg);
          this[`fileList${event.name}`].splice(event.index, 1)
          return false;
        }
        if (data.data) {
          this.form.files = data.data.files;
          this.show_files = true;
          let item = this[`fileList${event.name}`][fileListLen]

          this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
            status: 'success',
            message: '',
            url: result
          }))
          this[`fileList${event.name}`].splice(fileListLen, 1)
          fileListLen++
        }
      }
    },
    uploadFilePromise(url) {

      return new Promise((resolve, reject) => {
        let a = uni.uploadFile({
          url: this.$httpApi + '/api/common/upload', // 仅为示例，非真实的接口地址
          filePath: url,
          name: 'file',
          formData: {
            user: 'hy'
          },
          success: (res) => {
            console.log("uploadFile==>", res)
            setTimeout(() => {
              resolve(res.data)
            }, 1000)
          }
        });
      })
    },
    deleteclick(event) {
      let _this = this
      uni.showModal({
        title: '提示',
        content: '您确定要删除吗?',
        success: function(res) {
          if (res.confirm) {
            console.log("222", res)
            _this.show_files = !_this.show_files;
            _this.fileList1 = []
          } else if (res.cancel) {
            console.log('用户点击取消');
          }
        }
      });
    }
  },
};
</script>
<style lang="scss" scoped>
@import "@/static/assets/css/index.css";
@import "@/static/assets/css/mobiscroll.core-2.5.2.css";
@import "@/static/assets/css/mobiscroll.animation-2.5.2.css";
@import "@/static/assets/css/mobiscroll.android-ics-2.5.2.css";

.check_men {
  margin-top: 20px;
  height: 18px;
  line-height: 18px;
  background: url('@/static/assets/images/icon-user.png') no-repeat center left;
  background-size: auto 100%;
  padding-left: 20px;
}

.imgs-box2 {
  display: flex;
  flex-direction: row;
  flex-flow: wrap;
  margin-top: 20px;
}

.user-img2 {
  width: 128px;
  height: 40px;
  line-height: 40px;
  background: #F2F4F3;
  border-radius: 4px 4px 4px 4px;
  position: relative;
  margin-right: 20px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: row;
  justify-content: start;
  align-items: center;

}


.user-img2 img {
  margin: 2px;
  width: 35px;
  height: 35px;
  margin-right: 5px;
  border-radius: 4px 4px 4px 4px;
}

.user-img2 .del {
  width: 14px;
  height: 14px;
  position: absolute;
  right: 5px;
  top: calc(50% - 7px);
  border-radius: 50%;
  background: #F0F0F0 url('@/static/assets/images/del_2.png') no-repeat center center;
  background-size: 100% 100%;
}

.pic_user {
  width: 38px;
  height: 38px;
  margin-bottom: 20px;
  background: #F0F0F0;
  border-radius: 4px 4px 4px 4px;
  background: #F0F0F0 url('@/static/assets/images/pick_user.png') no-repeat center center;
  background-size: 40% 40%;
}

.file-name {
  padding: 10px;
  background: #F8F9FC;
  border-radius: 8px 8px 8px 8px;
  display: flex;
  position: relative;
  width: 90vw;
}

.file-txt {
  width: 80%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.new-tip {
  position: absolute;
  right: 0px;
  top: 0;
  /* width: 30px;
  text-align: center;
  height: 16px;
  background: #FF7A00;
  border-radius: 0px 8px 0px 4px;
  font-size: 8px;
  color: #ffffff; */
}

.newForm {
  width: 100%;
  height: 150vh;
  background-color: #F8F8F8;
  margin-top: 40px;
}

.imgs-box {
  clear: both;
  margin-top: 20px;
  margin-right: -12px;
  display: flex;
  flex-direction: row;
  flex-flow: wrap;
}


.user-img {
  width: 38px;
  height: 38px;
  border-radius: 4px 4px 4px 4px;
  margin-bottom: 20px;
  margin-right: 20px;
  position: relative;
}
.item-img-bg{
  width:80rpx;
  height:80rpx;
  border-radius: 50%;
  background-color: #4871C0;
  color: #ffffff;
  font-size: 20rpx;
  text-align: center;
  line-height: 80rpx;
}
.user-img img {
  width: 100%;
  height: 100%;
  border-radius: 4px 4px 4px 4px;
}

.user-img .del {
  width: 14px;
  height: 14px;
  position: absolute;
  right: -7px;
  top: -7px;
  border-radius: 50%;
  background: #F0F0F0 url('@/static/assets/images/del_user.png') no-repeat center center;
  background-size: 100% 100%;
}

.pic_user {
  width: 38px;
  height: 38px;
  margin-bottom: 8px;
  background: #F0F0F0;
  border-radius: 4px 4px 4px 4px;
  background: #F0F0F0 url('@/static/assets/images/pick_user.png') no-repeat center center;
  background-size: 40% 40%;
}

.u-flex {
  display: flex;
  align-items: center;
}

.sponsor_box {
  width: 100%;
  background: #fff;
  padding: 10px 15px;
  box-sizing: border-box;

  /deep/ .u-upload__button {
    width: 38px !important;
    height: 38px !important;
  }
}

.sponsor_box .uploads {
  width: 38px;
  height: 38px;
}


.sponsor_name {
  width: 38px;
  font-size: 12px;
  color: #666;
  text-align: center;
  margin-top: 10px;
}

.all {
  font-size: 12px;
  color: #999;
  text-align: center;
  margin-top: 10px;
}

.form {
  background: #fff;
  font-size: 14px;
  padding-bottom: 80px;

  .btn {
    width: 100%;
    background: #fff;
    padding: 15px;
    box-sizing: border-box;
    display: flex;
    position: fixed;
    bottom: 0;
  }

  .cancelbtn {
    margin-right: 29px;
    color: #333;
    background: #F3F3F3;
    border: 0;
  }

  uni-button:after {
    border: 0;
  }
}

/deep/ .u-cell__body__content {
  min-width: 130rpx;
}

/deep/ .u-line {
  border: 0;
  border-bottom: 1px #F8F8F8 solid !important;
}

/deep/ .u-cell__value {
  color: #333;
}

/deep/ .u-cell__body {
  padding: 15px;
  font-size: 14px;
}

/deep/ .u-cell__title-text {
  font-size: 14px;
}

.ipt {
  width: 92%;
  margin-left: 4%;
  background: #F8F8F8;
  height: 40px;
  margin-top: 12px;
  box-sizing: border-box;
}

.line {
  width: 100%;
  height: 10px;
  background: #F8F8F8;

}

.textarea {
  padding: 6px;
  border-bottom: 1px #F8F8F8 solid;
}

.textarea p {
  padding: 9px;
}

/deep/ .picker-view {
  width: 350px;
  height: 300px;
  margin-top: 10px;
}

/deep/ .uicon-close {
  z-index: 100;
}

/deep/ .item {
  height: 50px;
  align-items: center;
  justify-content: center;
  text-align: center;
}
</style>
